﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Entity;
using System.Data.SqlClient;
using System.Data;
namespace DataAccessLayer.Adapter
{
    public class TaiKhoanAdapter
    {
        clsKetNoiCSDL kn = new clsKetNoiCSDL();
        DataTable dt;
        public DataTable LoadTaiKhoan()
        {
            string sql = "tbTaiKhoan_SelectAll";
            dt = kn.LoadDL(sql);
            return dt;
        }
        public void ThemmTaiKhoa(clsTaiKhoan clTaiKhoan)
        {
            string sql = "tbTaiKhoan_InsertAcount";
            int Npa = 5;
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTK"; value[0] = clTaiKhoan.MaTK;
            name[1] = "@TenDangNhap"; value[1] = clTaiKhoan.TenDangNhap;
            name[2] = "@MatKhau"; value[2] = clTaiKhoan.MatKhau;
            name[4] = "@MaNV"; value[4] = clTaiKhoan.MaNV;
            name[3] = "@Quyen"; value[3] = clTaiKhoan.Quyen.ToUpper();
            kn.UpdateDL(sql, name, value, Npa);
        }
        public void SuaTaiKhoan(clsTaiKhoan clTaiKhoan)
        {
            string sql = "tbTaiKhoan_UpdateAcount";
            int Npa = 5;
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTK"; value[0] = clTaiKhoan.MaTK;
            name[1] = "@TenDangNhap"; value[1] = clTaiKhoan.TenDangNhap;
            name[2] = "@MatKhau"; value[2] = clTaiKhoan.MatKhau;
            name[3] = "@Quyen"; value[3] = clTaiKhoan.Quyen;
            name[4] = "@MaNV"; value[4] = clTaiKhoan.MaNV;
            kn.UpdateDL(sql, name, value, Npa);
        }
        public void XoaTaiKhoan(clsTaiKhoan clTaiKhoan)
        {
            string sql = "tbTaiKhoan_DeleteAcount";
            int Npa = 1;
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTK"; value[0] = clTaiKhoan.MaTK;
            kn.UpdateDL(sql, name, value, Npa);
        }
        public DataTable Login(clsTaiKhoan clTaiKhoan)
        {
            int Npa = 2;
            string sql = "tbTaiKhoan_Login";
            string []name=new string[Npa];
            object[]value=new object[Npa];
            name[0] = "@TenDangNhap"; value[0] = clTaiKhoan.TenDangNhap;
            name[1] = "@MatKhau"; value[1] = clTaiKhoan.MatKhau;
            dt = new DataTable();
            dt = kn.LoadDL(sql,name,value,Npa);
            return dt;
        }
        object kq;
        public object KiemTraTrungMa(clsTaiKhoan clsTK)
        {
            string sql = "tbTaiKhoan_KiemTraMa";
            int N = 1;
            string []name=new string[N];
            object[] value = new object[N];
            name[0] = "@MaTK"; value[0]=clsTK.MaTK;
            kq = kn.KTTrungMa(sql,name,value,N);
            return kq;
        }
        public object KiemTraTrungTen(clsTaiKhoan clsTK)
        {
            string sql = "tbTaiKhoan_KiemTraTen";
            int N = 1;
            string[] name = new string[N];
            object[] value = new object[N];
            name[0] = "@TenDangNhap"; value[0] = clsTK.TenDangNhap;
            kq = kn.KTTrungMa(sql, name, value, N);
            return kq;
        }
    }
}
